package net.zoneland.knowledge.model;

import java.io.Serializable;
import net.zoneland.knowledge.model.TreeNode;

public class Resource implements Serializable, Comparable<Resource> {

    private static final long serialVersionUID = -1L;

    private String id;

    private String name;

    private String pid;

    private String resourceType;

    private Integer orders;

    private String scriptUrls;

    private String description;

    private String icon;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid == null ? null : pid.trim();
    }

    public String getResourceType() {
        return resourceType;
    }

    public void setResourceType(String resourceType) {
        this.resourceType = resourceType == null ? null : resourceType.trim();
    }

    public Integer getOrders() {
        return orders;
    }

    public void setOrders(Integer orders) {
        this.orders = orders;
    }

    public String getScriptUrls() {
        return scriptUrls;
    }

    public void setScriptUrls(String scriptUrls) {
        this.scriptUrls = scriptUrls == null ? null : scriptUrls.trim();
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description == null ? null : description.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon == null ? null : icon.trim();
    }

    @Override
    public int compareTo(Resource object) {
        if (this.orders == null) {
            this.orders = 0;
        }
        if (object.orders == null) {
            object.orders = 0;
        }
        if (this.orders > object.orders) {
            return 1;
        } else if (this.orders < object.orders) {
            return -1;
        }
        return 0;
    }

    public TreeNode<Resource> toTree() {
        TreeNode<Resource> tree = new TreeNode<>();
        tree.setId(this.id);
        tree.setpId(this.pid);
        tree.setData(this);
        tree.setName(this.name);
        return tree;
    }
}
